package woa.tree.binary;

import java.util.ArrayList;
import java.util.List;

/**
 * 二叉树的中序遍历
 *
 * @author wangpeng
 * @date 2021/12/3
 */
public class InorderTraversal {

    public static List<Integer> inorderTraversal(TreeNode root) {
        List<Integer> rs = new ArrayList<>();
        dfs(rs, root);
        return rs;
    }

    public static void dfs(List<Integer> rs, TreeNode root) {
        if (root == null) {
            return;
        }
        dfs(rs, root.left);
        rs.add(root.val);
        dfs(rs, root.right);
    }

    public static void main(String[] args) {
        TreeNode root = new TreeNode(1);
        System.out.println(inorderTraversal(root));
    }
}
